package algotithm.weekendrace.leetcode244.test1;

/**
 * @author 25068
 * @Date 2021/6/6 10:29
 * @Title 5776. 判断矩阵经轮转后是否一致
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] mat = {{0,1},{1,0}};
        int[][] target = {{1,0},{0,1}};
        boolean res = solution.findRotation(mat, target);
        System.out.println(res);
    }

    public boolean findRotation(int[][] mat, int[][] target) {
        boolean res = false;
        for (int i = 0; i < 4 ;i++) {
            rotate(mat);
            res = isSimple(mat,target);
            if (res) {
                return res;
            }
        }
        return res;
    }

    public boolean isSimple(int[][] arr1,int[][] arr2) {
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0 ; j < arr2.length; j++) {
                if (arr1[i][j] != arr2[i][j]) {
                    return false;
                }
            }
        }
        return true;
    }



    public void rotate(int[][] matrix) {
        int n = matrix.length;
        // 水平翻转
        for (int i = 0; i < n / 2; ++i) {
            for (int j = 0; j < n; ++j) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[n - i - 1][j];
                matrix[n - i - 1][j] = temp;
            }
        }
        // 主对角线翻转
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < i; ++j) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }
    }
}
